package org.jeecgframework.core.common.model.json;

import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.jeecg.common.ExceptionCode;

/**
 * $.ajax后需要接受的JSON
 * 
 * @author
 * 
 */

public class AjaxJson {

	private boolean success = true;// 是否成功
	private int code = ExceptionCode.ok.getCode();
	private String msg = "操作成功";// 提示信息
	private Object obj = null;// 其他信息
	private Map<String, Object> attributes;// 其他参数
	
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}
	
	public AjaxJson() {
	}
	
	public AjaxJson(boolean success, int code, String msg, Object obj) {
	    this.success = success;
	    this.code = code;
	    this.msg = msg;
	    this.obj = obj;
	  }

	public Map<String, Object> getAttributes() {
		return attributes;
	}

	public void setAttributes(Map<String, Object> attributes) {
		this.attributes = attributes;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}
	public String getJsonStr(){
		JSONObject obj = new JSONObject();
		obj.put("success", this.isSuccess());
		obj.put("msg", this.getMsg());
		obj.put("obj", this.obj);
		obj.put("attributes", this.attributes);
		return obj.toJSONString();
	}
	 public static AjaxJson ok(Object obj) {
		    return new AjaxJson(true, ExceptionCode.ok.getCode(), "操作成功", obj);
		  }
}
